#include "operation.h"

GtkWidget *create_operation_window()
{
    window_operation = gtk_window_new(GTK_WINDOW_TOPLEVEL);

    // 显示窗口标题
    gtk_window_set_title((GtkWindow *)window_operation, "StuMgt学生信息管理系统");
    // 显示窗口大小
    gtk_widget_set_size_request(window_operation, 400, 300);
    // 窗口位置设置：总是居中
    gtk_window_set_position((GtkWindow *)window_operation, GTK_WIN_POS_CENTER_ALWAYS);
    // 窗口销毁 即程序结束
    g_signal_connect(window_operation, "destroy", G_CALLBACK(gtk_main_quit), NULL);

    /*--------------------------------容器---------------------------*/

    // 创建容器大小为1024*600
    GtkWidget *table = gtk_table_new(300, 400, TRUE);
    // 容器加入窗口
    gtk_container_add(GTK_CONTAINER(window_operation), table);

    int start_x = 150;
    int end_x = 250;
    int stert_y = 35;
    int end_y = 65;

    // 显示数据按钮
    GtkWidget *show_data_btn = gtk_button_new_with_label("显示所有数据");
    // 把按钮加入布局
    gtk_table_attach_defaults(GTK_TABLE(table), show_data_btn, start_x, end_x, stert_y, end_y);
    // 修改数据按钮
    GtkWidget *modify_data_btn = gtk_button_new_with_label("修改数据");
    // 把按钮加入布局
    gtk_table_attach_defaults(GTK_TABLE(table), modify_data_btn, start_x, end_x, stert_y + 100, end_y + 100);
    // 返回按钮
    GtkWidget *go_back_btn = gtk_button_new_with_label("返回");
    // 把按钮加入布局
    gtk_table_attach_defaults(GTK_TABLE(table), go_back_btn, start_x, end_x, stert_y + 200, end_y + 200);

    // 打开显示数据窗口
    g_signal_connect(show_data_btn, "clicked", G_CALLBACK(hide_window), window_operation);
    g_signal_connect(show_data_btn, "clicked", G_CALLBACK(show_window), "window_showdata");

    // 打开修改数据窗口
    g_signal_connect(modify_data_btn, "clicked", G_CALLBACK(hide_window), window_operation);
    g_signal_connect(modify_data_btn, "clicked", G_CALLBACK(show_window), "window_modifydata");

    // 返回窗口
    g_signal_connect(go_back_btn, "clicked", G_CALLBACK(hide_window), window_operation);
    g_signal_connect(go_back_btn, "clicked", G_CALLBACK(show_window), "window_homepage");

    return window_operation;
}